import time
def show_progress(total=10):
    """
    显示进度条
    """
    for i in range(total+1):
        progress= i * 10
        bar = "#" * i # 0,1,2,3,4,5,6,7,8,9,10
        print(f"\r进度: [{bar:<10}] {progress}%", end="", flush=True)
        time.sleep(0.1)
    print()

show_progress()


def debug_print(*args,level="INFO"):
    """带有日志级别和颜色的调试输出"""
    # ansi 转义序列
    colors = {
        "INFO": "\033[94m",  # 蓝色
        "DEBUG": "\033[92m",  # 绿色
        "WARNING": "\033[93m",  # 黄色
        "ERROR": "\033[91m",  # 红色
    }   

    color = colors.get(level, "\033[0m")  # 默认颜色为重置
    reset = "\033[0m"  # 重置颜色
    timestamp = time.strftime("%Y-%m-%d %H:%M:%S") # 日期格式化年月日时分秒
    #print(f"{color}[{level}] {timestamp}: {reset}", *args)
    print(f"{color}[{level}] {timestamp}:", *args, reset)


debug_print("程序启动", level="INFO")
debug_print("读取配置文件", level="DEBUG")
debug_print("磁盘空间不足", level="WARNING")
debug_print("文件打开失败", level="ERROR")